
//
//  ChooseCountryViewController.m
//  AoJi
//
//  Created by MinwenYi on 15-2-12.
//  Copyright (c) 2015年 xuanheng. All rights reserved.
//

#import "ChooseCountryViewController.h"

#import "DataSingleTon.h"

#import "FangAnTableViewCell.h"
#import "PPiFlatSegmentedControl.h"
#import "NSString+FontAwesome.h"
#import "successDemoView.h"
#import "CustomButton.h"
#import "goldenViewer.h"
#import "aojiUSA.h"
#import "CustomPickerView.h"
#import "QZTableViewCell.h"
#import "RecTableViewCell.h"
#import "SchoolDireViewController.h"
#import "CustomPopTableview.h"
#import "SearchTableViewController.h"
typedef NS_ENUM(NSInteger,DegreeCategory)
{
    TypeAll,
    TypeRecommond,
    TypeMiddle,
    TypeColleg,
    

    
};
const static  int  secSegItemWidth=60;
@interface ChooseCountryViewController ()<UITableViewDataSource,UITableViewDelegate,UITextViewDelegate,CustomPopTableviewDelegate>
{
    UILabel *citylabel;

    CustomPopTableview *popview;
    
    NSMutableArray *schoolAreaArray;
    int cityId;
    
    
    UIView  * moreCountryView;
    NSMutableArray  *itemArray;
    NSArray *names;
    DegreeCategory requestType;
    UIButton *allMoreImg;
    
  
    UIButton *moreBtn;
    
    UILabel *otherplaceholder;
    UILabel *notePH;
    
    
    UIButton *maleBtn;
    UIButton *femaleBtn;
    
    
    NSMutableArray *goAbroadTimeArray;
    int tapIndex;
    
    
    UIView *view0;
    UIScrollView *view1;
    UIView *view2;
    UIView *view3;
    UIView *view4;
    UIView *view5;
    UIView *view6;
    UIScrollView *baseScrollview;
    
    int lastBtnInfo;
    
    //院校指南
    UILabel  *lastSelectLabel;
    
    
    UITableView *highSchoolTable;
    UITableView  *undergraduTable;
    UITableView *postgraduTable;
    
    UIScrollView *contentScrollview;
    
    
    //留学方案
    int showIndex;
    
    NSMutableArray *gradesArray;
    
    //
    NSMutableArray *   highschoolArray;
    NSMutableArray *   undergraduArray;
    NSMutableArray *   postgraduArray;
    
    NSMutableDictionary *highschoolDic;
    NSMutableDictionary *undergraduDic;
    NSMutableDictionary *postgraduDic;
    
    //顶部7段
    NSMutableArray *topSegArray;
    
    
    
    UITableView* successTableView;
    
    
    UIView *pickerBgview;
    CustomPickerView *picker;
    NSMutableArray *pickerShowingArray;
    UITextField *showingtemField;
    
    
    NSMutableArray *yixiangguojiaArray;
    NSMutableArray *xueweiArray;
    NSArray *xueliArray;
    NSArray *biyeleibieArray;
    NSArray *yuyanArray;
    NSMutableArray *nianfenArray;
    
    NSMutableDictionary *provinceDic;
    NSMutableArray *shengshiArray;
    NSArray *cityArray;
    NSString *temSelectStr;
    
    UITextField *editingFeild;
    
    MBProgressHUD *hudNull;
    
    //院校指南
    UITableView *rectableview;
    NSMutableArray *recArray;
    
    ///签证办理
    NSMutableArray *qianZhengArray;
    UITableView *qianzhengTableview;
    
    BOOL isFirsTap;
    
    
    UIButton *searchBtn;

}
@end

@implementation ChooseCountryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    searchBtn=[[UIButton alloc]initWithFrame:CGRectMake(Mainwidth-10-54/2, 30, 54/2, 54/2)];
    [self.view addSubview:searchBtn];
    [searchBtn setImage:[UIImage imageNamed:@"shousuo@2x.png"] forState:UIControlStateNormal];
    [searchBtn addTarget:self action:@selector(tapToSearch) forControlEvents:UIControlEventTouchUpInside];
    
    searchBtn.hidden=YES;
    
    

    
    yixiangguojiaArray=[NSMutableArray arrayWithObjects:
                        @"澳大利亚",@"英国",@"加拿大",@"美国",@"德国",@"瑞士",
                        @"荷兰",@"法国",@"爱尔兰",@"日本",@"韩国",@"俄罗斯",
                        @"乌克兰",@"新加坡",@"马来西亚",@"新西兰",@"南非",@"希腊",
                        @"丹麦",@"芬兰",@"挪威",@"瑞典",@"比利时",@"爱沙尼亚",
                        @"西班牙",@"马耳他",@"意大利",@"奥地利",@"列支敦士登",@"波兰",
                        @"中国香港",@"中国台湾",@"泰国",@"塞浦路斯",@"也门",@"突尼斯",
                        @"中国",@"北欧",nil];
    xueweiArray=[NSMutableArray arrayWithObjects:
                 @"本科",@"硕士",@"博士",@"MBA",@"预科",@"语言中心",
                 @"专科",@"网校",nil];
    xueliArray=[NSArray arrayWithObjects:
                @"本科",@"硕士",@"博士",@"MBA",@"预科",@"语言中心",
                @"专科",@"网校",nil];
    yuyanArray=[NSArray arrayWithObjects:
                @"托福",@"雅思",@"SAT",@"GRE",@"GMAT",@"LSAT",
                @"MCAT",@"SSAT",@"TEF",@"JLPT",@"TeatDaf",@"其他",
                nil];
    biyeleibieArray=[NSArray arrayWithObjects:
                     @"普通高中",@"重点高中",@"本科",@"高职专科",@"独立学院",@"211工程",@"985工程",nil];
    nianfenArray=[NSMutableArray array];
    
    for (int i=1965; i<2005; i++) {
        [nianfenArray addObject:[NSString stringWithFormat:@"%i",i]];
    }
    
    
    NSString *path=[[NSBundle mainBundle]pathForResource:@"Provinces.plist" ofType:nil];
    
    provinceDic=[NSMutableDictionary dictionaryWithContentsOfFile:path];
    shengshiArray=[NSMutableArray arrayWithArray:[provinceDic allKeys]];
    
    
    
    NSDictionary *temDic=[DataSingleTon shareDataSingleTon].countryList[self.tagId];
    self.countryId=[[temDic objectForKey:@"id"] intValue];
    [DataSingleTon shareDataSingleTon].countryId=self.countryId;
    self.catdir=[temDic objectForKey:@"catdir"];
    [DataSingleTon shareDataSingleTon].catdir=self.catdir;

    
    self.ctitleLabel.text=[NSString stringWithFormat:@"%@留学",[temDic objectForKey:@"name"]];
    self.countryName=[temDic objectForKey:@"name"];
    
    UIScrollView *sectionview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,self.headerHeight, Mainwidth-50, 42)];
    sectionview.showsHorizontalScrollIndicator=NO;
    sectionview.backgroundColor=kheadBgcolor;
    
    [self.view addSubview:sectionview];
    
    
    
    
    moreBtn=[[UIButton alloc]initWithFrame:CGRectMake(Mainwidth-50,self.headerHeight, 50, 42)];
    moreBtn.backgroundColor=kheadBgcolor;
    
    [self.view addSubview:moreBtn];
    
    [moreBtn setImage:[UIImage imageNamed:@"gengduoxia@2x.png"] forState:UIControlStateNormal];
    [moreBtn setImage:[UIImage imageNamed:@"gengduoshang@2x.png"] forState:UIControlStateSelected];
    [moreBtn addTarget:self action:@selector(tapMoreBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *shadowview=[[UIView alloc]initWithFrame:CGRectMake(viewLeft(moreBtn)-23/4, viewTop(moreBtn), 23/2, 50)];
    shadowview.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"yingyin@2x.png"]];
    [self.view addSubview:shadowview];

    
    
    NSString *ite=[NSString stringWithFormat:@"澳际%@",[temDic objectForKey:@"name"]];
    
    names=[NSArray arrayWithObjects:@"留学方案",@"留学测评",@"院校指南",@"签证办理",@"成功案例",@"金牌顾问",ite, nil];
    
    topSegArray=[NSMutableArray array];
    
    for (int i=0; i<7; i++)
    {
        UIButton *itemBtn=[[UIButton alloc]initWithFrame:CGRectMake(60*i, 0, 60, 40)];
        [itemBtn setTitle:names[i] forState:UIControlStateNormal];
       
        [itemBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [itemBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
        
        if (i==0) {
            itemBtn.selected=YES;
            lastBtnInfo=i;
        }
        
        itemBtn.tag=i;
        itemBtn.titleLabel.font=[UIFont systemFontOfSize:12];
        
        [itemBtn addTarget:self action:@selector(tapThtBtn:) forControlEvents:UIControlEventTouchUpInside];
        
        [sectionview addSubview:itemBtn];
        
        
        [topSegArray addObject:itemBtn];
    }
    
    sectionview.contentSize=CGSizeMake(60*7, 0);
    
    
    UIView  *topLine=[[UIView alloc]initWithFrame:CGRectMake(0,viewTop(sectionview), Mainwidth, 1)];
    UIView *bottomLine=[[UIView alloc]initWithFrame:CGRectMake(0,viewBottom(sectionview), Mainwidth, 1)];
    
    
    topLine.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"fengjiaxian-x.png"]];
    bottomLine.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"fengjiaxian-x.png"]];
    [self.view  addSubview:topLine];
    [self.view addSubview:bottomLine];
    

    
    
    baseScrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, viewBottom(sectionview)+1, Mainwidth, MainHeight-viewBottom(sectionview))];
    baseScrollview.delegate=self;
    [self.view addSubview:baseScrollview];
    baseScrollview.showsHorizontalScrollIndicator=NO;
    
    baseScrollview.backgroundColor=[UIColor whiteColor];
    baseScrollview.contentSize=CGSizeMake(Mainwidth*7, 0);
    baseScrollview.pagingEnabled=YES;
   
//     [baseScrollview addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
    
    [self changeView];

    
    
    [self getFangAn];
    
//    [self udergraduData];
//    [self postgraduData];
    
    int contentY=10;
    
    if (![self.countryName isEqual:@"欧洲"]&&![self.countryName isEqual:@"亚洲"] )
    {
        
        [self GradeView];
        contentY=52;
    }
    
    
    
    
    [self dealView0:contentY];
    [self delaview1];
    [self dealview2];
    [self dealview3];
    [self dealview4];
    [self dealview5];
    [self dealview6];
    
}

-(void)GradeView
{

    UIView *bgView=[[UIView alloc]initWithFrame:CGRectMake(10, 5, Mainwidth-20, 42)];
    bgView.layer.borderColor=[self getCorlor:@"f7342f"].CGColor;
    bgView.layer.borderWidth=1.5;
    [view0 addSubview:bgView];
    
    
    gradesArray=[NSMutableArray array];
    
    int itemwidth=viewWidth(bgView)/3;
    
    
   
    
    NSArray *names=[NSArray arrayWithObjects:@"高中",@"本科",@"研究生", nil];
    
    for (int i=0; i<3; i++)
    {
        UILabel *item=[[UILabel alloc]initWithFrame:CGRectMake(itemwidth*i, 1, itemwidth, 40)];
        [bgView addSubview:item];
        item.tag=i;
        item.text=names[i];
        item.font=[UIFont systemFontOfSize:14];
        item.textAlignment=NSTextAlignmentCenter;
        
        item.textColor=[self getCorlor:@"f7342f"];
        
        if (i==0) {
             item.backgroundColor=[self getCorlor:@"f7342f"];
            item.textColor=[UIColor whiteColor];
            
        }
        
        
        UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapgradeName:)];
        
        [item addGestureRecognizer:tap];
        item.userInteractionEnabled=YES;
        [gradesArray addObject:item];
    }
    
    
    
    for (int i=1; i<3; i++) {
        UIView *sepLine=[[UIView alloc]initWithFrame:CGRectMake(itemwidth*i, 0, 1.5, 42)];
        [bgView addSubview:sepLine];
        sepLine.backgroundColor=[self getCorlor:@"f7342f"];
    }

}

-(void)tapgradeName:(UIGestureRecognizer *)ges
{
    
    
    
    
    showIndex=[ges view].tag;
    
    
    
    
    for (int i=0; i<3; i++)
    {
        
        UILabel *item=gradesArray[i];
        
        if (i==showIndex)
        
        {
                item.backgroundColor=[self getCorlor:@"f7342f"];
                item.textColor=[UIColor whiteColor];
          
        }else
        {
            item.backgroundColor=[self getCorlor:@"FFFFFF"];
        
            item.textColor=[self getCorlor:@"f7342f"];
        }
    }
    
    contentScrollview.contentOffset=CGPointMake(showIndex*Mainwidth, 0);
    [self switchTable:showIndex];

}

-(void)changeView
{

    view0=[[UIView alloc]initWithFrame:CGRectMake(0, 0,Mainwidth,viewHeight(baseScrollview))];
    [baseScrollview addSubview:view0];
    
    view0.backgroundColor=[self getCorlor:@"f0f0f0"];
   

    view1=[[UIScrollView alloc]initWithFrame:CGRectMake(Mainwidth, 0,Mainwidth,viewHeight(baseScrollview))];
    view1.showsVerticalScrollIndicator=NO;
    [baseScrollview addSubview:view1];
    view2=[[UIView alloc]initWithFrame:CGRectMake(Mainwidth*2, 0,Mainwidth,viewHeight(baseScrollview))];
    [baseScrollview addSubview:view2];
    
    view3=[[UIView alloc]initWithFrame:CGRectMake(Mainwidth*3, 0,Mainwidth,viewHeight(baseScrollview))];
    [baseScrollview addSubview:view3];
    
    
    view4=[[UIView alloc]initWithFrame:CGRectMake(Mainwidth*4, 0,Mainwidth,viewHeight(baseScrollview))];
    [baseScrollview addSubview:view4];
    
    view5=[[UIView alloc]initWithFrame:CGRectMake(Mainwidth*5, 0,Mainwidth,viewHeight(baseScrollview))];
    [baseScrollview addSubview:view5];
    view6=[[UIView alloc]initWithFrame:CGRectMake(Mainwidth*6, 0,Mainwidth,viewHeight(baseScrollview))];
    [baseScrollview addSubview:view6];

}


#pragma mark -顶部7项切换

-(void)tapThtBtn:(UIButton *)sender
{

    if (sender.tag!=lastBtnInfo) {
        sender.selected=YES;
        
        UIButton *tem=topSegArray[lastBtnInfo];
        tem.selected=NO;
//        lastBtnInfo=(int)sender.tag;
        [self tapSlideSegmentItem:lastBtnInfo currentIndex:(int)sender.tag Items:topSegArray];
        
        baseScrollview.contentOffset=CGPointMake(Mainwidth*sender.tag,0 );
        NSInteger indexNum =(NSInteger)sender.tag;
        NSLog(@"lalala:%ld",(long)indexNum);
        
        
        
        
        
    }


}












-(void)dealView0:(int)contHeight   //留学方案
{
    
    
    
    
    highschoolArray=[NSMutableArray array];
    
    contentScrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, contHeight, Mainwidth,viewHeight(view0)-contHeight)];
    contentScrollview.pagingEnabled=YES;
    contentScrollview.delegate=self;
   
    [view0 addSubview:contentScrollview];
    highSchoolTable=[[UITableView alloc]initWithFrame:CGRectMake(10, 0, Mainwidth-20, viewHeight(contentScrollview)) style:UITableViewStyleGrouped];
    [highSchoolTable registerClass:[FangAnTableViewCell class] forCellReuseIdentifier:@"cell"];
    [contentScrollview addSubview:highSchoolTable];
    highSchoolTable.delegate=self;
    highSchoolTable.dataSource=self;
    
    
    if (contHeight!=10) {
        undergraduTable=[[UITableView alloc]initWithFrame:CGRectMake(Mainwidth+10, 0, Mainwidth-20, viewHeight(contentScrollview)) style:UITableViewStyleGrouped];
        [undergraduTable registerClass:[FangAnTableViewCell class] forCellReuseIdentifier:@"cell"];
        [contentScrollview addSubview:undergraduTable];
        undergraduTable.delegate=self;
        undergraduTable.dataSource=self;
        
        
        
        postgraduTable=[[UITableView alloc]initWithFrame:CGRectMake(Mainwidth*2+10, 0, Mainwidth-20, viewHeight(contentScrollview)) style:UITableViewStyleGrouped];
        [postgraduTable registerClass:[FangAnTableViewCell class] forCellReuseIdentifier:@"cell"];
        [contentScrollview addSubview:postgraduTable];
        postgraduTable.delegate=self;
        postgraduTable.dataSource=self;

        contentScrollview.contentSize=CGSizeMake(Mainwidth*3, 0);
    }
    
    
    
    
    
    
    highschoolDic=[NSMutableDictionary dictionary];
    undergraduDic=[NSMutableDictionary dictionary];
    postgraduDic=[NSMutableDictionary dictionary];
    
    
}


-(void)dealview4//成功案例
{
    successDemoView *successView = [[successDemoView alloc] initWithFrame:CGRectMake(0, 0, Mainwidth, viewHeight(view4))];
//    successView.frame = CGRectMake(0, 0, 320, 640);
    [view4 addSubview:successView];

}
-(void)dealview5//金牌顾问
{
    goldenViewer* goldView = [[goldenViewer alloc] initWithFrame:CGRectMake(0, 0, Mainwidth, viewHeight(view5))];
//    goldView.frame = CGRectMake(0, 0, 320, 640);
    [view5 addSubview:goldView];


}
-(void)dealview6//澳际美国
{


    aojiUSA* aojiView = [[aojiUSA alloc] initWithFrame:CGRectMake(0, 0, Mainwidth, viewHeight(view6))];
//    aojiView.frame = CGRectMake(0, 0, 320, 640);
    [view6 addSubview:aojiView];
    
 
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    if (tableView==highSchoolTable) {
        if ([[highschoolDic objectForKey:@(section)] isEqual:@"show"]) {
            return 2;
        }
        else{
            NSArray *tem=highschoolArray[section+1];
            
            return tem.count;
        }
    }else if (tableView==undergraduTable)
    {
        
        if ([[undergraduDic objectForKey:@(section)] isEqual:@"show"]) {
            return 2;
        }
        else{
            NSArray *tem=undergraduArray[section+1];
            
            return tem.count;
        }
    }
    else if (tableView==qianzhengTableview)
    {
        return qianZhengArray.count;
    }
    else if (tableView==rectableview)
    {
        int tem=recArray.count;
        return recArray.count;
    }
    else
    {
        
        if ([[postgraduDic objectForKey:@(section)] isEqual:@"show"])
        {
            return 2;
        }
        else
        {
            NSArray *tem=postgraduArray[section+1];
            
            return tem.count;
            
        }
    }
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==qianzhengTableview) {
        QZTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        int bgY;
        if (indexPath.row==0) {
            bgY=32/2;
        }else{
            bgY=22/2;
        }
        
        cell.bgImgview.frame=CGRectMake(40,bgY, Mainwidth-80, 80);
        
        NSString *imgName=[NSString stringWithFormat:@"list-%i",(int)indexPath.row%6+1];
        
        cell.bgImgview.image=[UIImage imageNamed:imgName];
        cell.numLabel.frame=CGRectMake(40+6,bgY-10, 89, 80);
        cell.numLabel.text=[NSString stringWithFormat:@"%02d",(int)indexPath.row+1];
        
        cell.contentLabel.frame=CGRectMake(132,bgY-10, 200, 80);
        cell.contentLabel.text=qianZhengArray[indexPath.row];
        
        return cell;
        
        
    }
    else if (tableView==rectableview)
    {
    
        RecTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        cell.paramdic=recArray[indexPath.row];
       
        return cell;
    
    }
    else{
    
    FangAnTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.titleLabel.frame=CGRectMake(5,5, Mainwidth-10,25);
    cell.titleLabel.font=[UIFont systemFontOfSize:14];
    cell.titleLabel.textColor=[self getCorlor:@"343333"];
    cell.titleLabel.textAlignment=NSTextAlignmentLeft;
   
    if (cell==nil) {
        cell=[[FangAnTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
       NSArray  *temArray;
    if (tableView==highSchoolTable) {
        temArray=highschoolArray[indexPath.section+1];
    }else if (tableView==undergraduTable){
    temArray=undergraduArray[indexPath.section+1];
    }else{
    
        temArray=postgraduArray[indexPath.section+1];

    }
    
    
    if (indexPath.row==0) {
        cell.titleLabel.text=[self removeEnd:temArray[0]];
        cell.titleLabel.textAlignment=NSTextAlignmentCenter;
       cell.titleLabel.font=[UIFont systemFontOfSize:15];
        cell.descriptionLabel.text=nil;
    }
    else{
    
    
    if (tableView==highSchoolTable) {
        cell.titleLabel.text=highschoolArray[0][indexPath.row];
    }else if (tableView==undergraduTable){
        cell.titleLabel.text=undergraduArray[0][indexPath.row];
    }else{
        
        
        
        cell.titleLabel.text=postgraduArray[0][indexPath.row];
        
    }
    }
    
    if (indexPath.row!=0) {
        
        
        NSMutableParagraphStyle *style=[[NSMutableParagraphStyle alloc]init];
        [style setMaximumLineHeight:20];
        [style setMinimumLineHeight:20];
        style.lineSpacing=1;
        
        NSMutableAttributedString *atts=[[NSMutableAttributedString alloc]initWithString:temArray[indexPath.row] attributes:@
        {
            
        NSParagraphStyleAttributeName:style,
            
        NSFontAttributeName:[UIFont systemFontOfSize:14],
            NSForegroundColorAttributeName:[self getCorlor:@"989898"],                                                                                                                      }];
        
         cell.descriptionLabel.attributedText=atts;
        cell.descriptionLabel.numberOfLines=0;
        
         cell.descriptionLabel.frame=CGRectMake(5 , 40, [self returnStringsize:temArray[indexPath.row]].width,[self returnStringsize:temArray[indexPath.row]].height);;
    }
   
    return cell;
    }
    
}




-(CGSize)returnStringsize:(NSString*)Str
{
    
    NSMutableParagraphStyle *style=[[NSMutableParagraphStyle alloc]init];
    [style setMaximumLineHeight:20];
    [style setMinimumLineHeight:20];
    style.lineSpacing=1;
    
 return   [Str boundingRectWithSize:CGSizeMake(viewWidth(highSchoolTable)-10, 600) options:NSStringDrawingUsesLineFragmentOrigin attributes:@
    {
        
    NSParagraphStyleAttributeName:style,
    NSFontAttributeName:[UIFont systemFontOfSize:14],
                                                                                                                                              
    
    } context:nil].size;

}

-(NSString *)removeEnd:(NSString*)str
{
    
    NSString *dexStr=nil;

    for (NSString *tem in [str componentsSeparatedByString:@"\n"]) {
        
        if (dexStr==nil) {
            dexStr=tem;
        }else{
            dexStr=[NSString stringWithFormat:@"%@ %@",dexStr,tem];
        
        }
    }
    
    
    return dexStr;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    if (tableView==highSchoolTable) {
        if (highschoolArray.count==0) {
            return 0;
        }
        else{
            
            return highschoolArray.count-1;
        }
        
    }else if (tableView==undergraduTable)
    {
        
        if (undergraduArray.count==0) {
            return 0;
        }
        else{
        
            return undergraduArray.count-1;
        }
        
    }
    else if (tableView==postgraduTable)
    {
        
        if (postgraduArray.count==0) {
            return 0;
        }
        else{
            return postgraduArray.count-1;
        }
        
    }else if (tableView==qianzhengTableview)
    {
        return 1;
    }else if (tableView==rectableview)
    {
        return 1;
    }
    else{
        return 0;
    }
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==qianzhengTableview) {
        int basehight=80;
        if (indexPath.row==0) {
            return basehight+32/2;
        }else if (indexPath.row==qianZhengArray.count-1)
        {
            return basehight+22;
        }else{
            return basehight+22/2;
        }
    }
    else if (tableView==rectableview)
    {
        return 70;
    }
    else
    {
    NSArray  *temArray;
    if (tableView==highSchoolTable)
    {
        temArray=highschoolArray[indexPath.section+1];
    }else if (tableView==undergraduTable)
    {
        temArray=undergraduArray[indexPath.section+1];
    }else if (tableView==postgraduTable)
    {
        
        temArray=postgraduArray[indexPath.section+1];
    }
       
    if (indexPath.row==0) {
       
        
        return 50;
    }else{
    
     return [self returnStringsize:temArray[indexPath.row]].height+50;
    }
        
    }
   
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (tableView==qianzhengTableview||tableView==rectableview) {
        return 0;
    }else{
        return 50;
    }
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    
    
    UIView *sectonFooterView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, Mainwidth, 50)];
    sectonFooterView.backgroundColor=[UIColor whiteColor];
    
    UIView *bottomview=[[UIView alloc]initWithFrame:CGRectMake(0, 46, Mainwidth, 4)];
    [sectonFooterView addSubview:bottomview];
    bottomview.backgroundColor=[self getCorlor:@"f0f0f0"];
    
    
    
    CustomButton *tapbtn=[[CustomButton alloc]initWithFrame:CGRectMake(Mainwidth/2-50/2, 0, 40, 40)];
    
    [tapbtn setImage:[UIImage imageNamed:@"jiantoushang.png"] forState:UIControlStateNormal];
    [tapbtn setImage:[UIImage imageNamed:@"jiantouxia.png"] forState:UIControlStateSelected];
    NSMutableDictionary *dic;
    
    if (tableView==highSchoolTable) {
        dic=highschoolDic;
    }else if (tableView==undergraduTable)
    {
        dic=undergraduDic;
    }else{
        dic=postgraduDic;
    }
    
    
    if ([[dic objectForKey:@(section)] isEqualToString:@"show"]) {
        tapbtn.selected=YES;
    }else{
     tapbtn.selected=NO;
    }
    
    [sectonFooterView addSubview:tapbtn];
    tapbtn.choosedTable=tableView;
    tapbtn.tag=section;
    
    if (tableView==highSchoolTable) {
        tapbtn.tapType=TypeHighSchool;
    }else if (tableView==undergraduTable)
    {
        
        tapbtn.tapType=Typeundergradu;
    }else{
        tapbtn.tapType=Typepostgradua;
        
    }
    
    tapbtn.sectionId=section;
    [tapbtn addTarget:self action:@selector(tapToHidOrShow:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    return sectonFooterView;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==rectableview) {
        SchoolDireViewController *vC=[[SchoolDireViewController alloc]init];
        
        NSString *tem=[NSString stringWithFormat:@"http://cent.dsgrd.com/study/school/detail?id=%@",[recArray[indexPath.row] objectForKey:@"id"]];
        vC.urlString=tem;
        vC.titlel=[recArray[indexPath.row] objectForKey:@"cschool"];
        [self.navigationController pushViewController:vC animated:YES];
    }

}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}

-(void)tapToHidOrShow:(CustomButton*)sender
{
    NSMutableDictionary *dic;
    
    NSIndexPath *path=[NSIndexPath indexPathForRow:0 inSection:sender.sectionId];
    
    
    NSLog(@"path:section=%i row=%i",path.section,path.row);
    
    if (sender.tapType==TypeHighSchool) {
        dic=highschoolDic;
    }else if (sender.tapType==Typeundergradu)
    {
        
        dic=undergraduDic;
    }else if (sender.tapType==Typepostgradua)
    {
        
        dic=postgraduDic;
    }
    
    if ( ![[dic objectForKey:@(sender.tag)] isEqual:@"show"]) {
        NSLog(@"yes");
        
        [dic setObject:@"show" forKey:@(sender.tag)];
        
        [sender.choosedTable reloadData];
        [sender.choosedTable scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
       
        
    }else{
        NSLog(@"no");
        [dic removeObjectForKey:@(sender.tag)];
        [sender.choosedTable reloadData];
        [sender.choosedTable scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
        
    }
    
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

    if (scrollView==contentScrollview) {
        
        showIndex=floor(scrollView.contentOffset.x)/Mainwidth;
        
        for (int i=0; i<3; i++)
        {
            
            UILabel *item=gradesArray[i];
            
            if (i==showIndex)
                
            {
                item.backgroundColor=[self getCorlor:@"f7342f"];
                item.textColor=[UIColor whiteColor];
                
            }else
            {
                item.backgroundColor=[self getCorlor:@"FFFFFF"];
                
                item.textColor=[self getCorlor:@"f7342f"];
            }
        }

        
        
        [self switchTable:showIndex];
        
        
    }else if (scrollView==baseScrollview)
    {
    
        int index=floor(scrollView.contentOffset.x)/Mainwidth;
//        UIButton *temBtn=topSegArray[lastBtnInfo];
//        temBtn.selected=NO;
//        UIButton *tem1=topSegArray[index];
//        tem1.selected=YES;
        
        [self tapSlideSegmentItem:lastBtnInfo currentIndex:index Items:topSegArray];
//        lastBtnInfo=index;
    
    }

    
//    self tapTheInFormationItem:
}




-(void)tapTheInFormationItem:(UIButton*)sender
{
    NSMutableArray *temArr=names;
    
    
    if (sender.tag!=lastBtnInfo) {
        UIButton *temBtn=temArr[lastBtnInfo];
        temBtn.selected=NO;
        UIButton *temBtn1=temArr[sender.tag];
        temBtn1.selected=YES;
        UIScrollView *temScrollview=(UIScrollView*)[temBtn1 superview];
        int temcurr=(int)sender.tag;
        
        if (sender.tag>lastBtnInfo)
        {
            if ((temcurr+1)*secSegItemWidth+60>viewWidth(temScrollview)) {
                int tem=(int)viewLeft(temBtn1)-2*secSegItemWidth>(int)temScrollview.contentSize.width-(int)viewWidth(temBtn1.superview)?temScrollview.contentSize.width-viewWidth(temScrollview):(int)sender.tag*secSegItemWidth-2*secSegItemWidth;
                temScrollview.contentOffset=CGPointMake(tem, 0);
            }
            
        }
        else if (sender.tag<lastBtnInfo)
        {
            if ((int)sender.tag*secSegItemWidth-60<temScrollview.contentOffset.x) {
                int tem=temcurr-2>0?temcurr-2:0;
                temScrollview.contentOffset=CGPointMake(tem*60, 0);
            }
            
            
        }
        
        lastBtnInfo=(int)sender.tag;
    }
    
}



-(void)switchTable:(int)index
{
    switch (index) {
        case 0:
            [self getFangAn];
            break;
        case 1:
            [self udergraduData];
            break;
        case 2:
            [self postgraduData];
            break;
            
        default:
            break;
    }

}

-(void)tapToSearch
{
    SearchTableViewController *vc=[[SearchTableViewController alloc]init];
    vc.catdir=self.catdir;
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */




-(void)getFangAn
{
    
    
    //    undergradu
    //    postgradua
    
    //cent.dsgrd.com/study/abroad?country=us&educational=high_school
    
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:self.catdir forKey:@"country"];
    [dic setObject:@"high_school" forKey:@"educational"];
    [dic setObject:@"0" forKey:@"type"];
    
    //study/abroad?country=us&educational=high_school&type=0
    
    [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:dic WithApi:@"study/abroad" WhenSuccess:^(NSMutableDictionary *response) {
        highschoolArray=response;
        [highSchoolTable reloadData];
    } WhenFailure:^(NSError *failure) {
        
    }];
    
     }


-(void)udergraduData
{
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:self.catdir forKey:@"country"];
  
    [dic setObject:@"0" forKey:@"type"];
    [dic setObject:@"undergradu" forKey:@"educational"];
    
        [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:dic WithApi:@"study/abroad" WhenSuccess:^(NSMutableDictionary *response) {
            undergraduArray=response;
            [undergraduTable reloadData];
        } WhenFailure:^(NSError *failure) {
    
        }];

}
-(void)postgraduData
{

    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:self.catdir forKey:@"country"];
    
    [dic setObject:@"0" forKey:@"type"];
    [dic setObject:@"postgradua" forKey:@"educational"];
    
    
    [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:dic WithApi:@"study/abroad" WhenSuccess:^(NSMutableDictionary *response) {
            postgraduArray=response;
            [postgraduTable reloadData];
        } WhenFailure:^(NSError *failure) {
    
        }];
    


}




-(void)delaview1  //留学测评
{
    pickerBgview=[[UIView alloc]initWithFrame:CGRectMake(0,MainHeight-200, Mainwidth, 200)];
    
    UIButton *confirmBtn=[[UIButton alloc]initWithFrame:CGRectMake(10, 0,40, 40)];
    [confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
    
    confirmBtn.tag=0;
    [confirmBtn addTarget:self action:@selector(confirmOrCancel:) forControlEvents:UIControlEventTouchUpInside];
    
    [pickerBgview addSubview:confirmBtn];
    
   
    
    UIButton *cancelBtn=[[UIButton alloc]initWithFrame:CGRectMake(Mainwidth-50, 0,40, 40)];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    
    [pickerBgview addSubview:cancelBtn];
    cancelBtn.tag=1;
    [cancelBtn addTarget:self action:@selector(confirmOrCancel:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    picker=[[CustomPickerView alloc]initWithFrame:CGRectMake(0,30, Mainwidth, 200)];
    picker.dataSource=self;
    picker.delegate=self;
    [pickerBgview addSubview:picker];
    
    int leftx=155;
    int temheight=63/2;
    
    UIView *topbgView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, Mainwidth, 5)];
    topbgView.backgroundColor=[self getCorlor:@"f0f0f0"];
    [view1 addSubview:topbgView];
    
    

    UILabel *topseg0=[[UILabel alloc]initWithFrame:CGRectMake(0, 5, Mainwidth, 63/2)];
    [self setTopSeg:topseg0 text:@"留学评估信息"];
    //留学意向国家
    NSString *intrealaTes=@"留学意向国家";
    UILabel *intreLabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(topseg0)+10, [self getStringwidth:intrealaTes fontSize:14], 18)];
    [self setLabel:intreLabel text:intrealaTes rightStar:YES bottomLine:YES];
    
    

    chosecountryf=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(intreLabel)-5, 200,temheight)];
    [self settextFeild:chosecountryf havMoreImage:YES placeHolder:@"请选择国家"];
    
    
   
    
    //留学意向院校
    NSString *intschoolTes=@"留学意向院校";
    UILabel *intreschoolLabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(intreLabel)+25, [self getStringwidth:intschoolTes fontSize:14], 18)];
    [self setLabel:intreschoolLabel text:intschoolTes rightStar:NO bottomLine:YES];
    
    
    
    yixiangyuanxiaof=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(intreschoolLabel)-5, 200,temheight)];
    [self settextFeild:yixiangyuanxiaof havMoreImage:NO placeHolder:@"请输入留学意向院校"];
    
    //意向专业
    
    NSString *intmaijor=@"意向专业";
    UILabel *intresmajor=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(intreschoolLabel)+25, [self getStringwidth:intmaijor fontSize:14], 18)];
    [self setLabel:intresmajor text:intmaijor rightStar:NO bottomLine:YES];
    
    
    yixiangzhuanyef=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(intresmajor)-5, 200,temheight)];
    [self settextFeild:yixiangzhuanyef havMoreImage:NO placeHolder:@"请输入留学意向院校"];
    
    //我要读的学位
    
    NSString *maymaijor=@"我要读的学位";
    UILabel *maymaijorlabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(intresmajor)+25,[self getStringwidth:maymaijor fontSize:14], 18)];
    [self    setLabel:maymaijorlabel text:maymaijor rightStar:YES bottomLine:YES];
    
    chosexueweif=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(maymaijorlabel)-5, 200,temheight)];
    [self settextFeild:chosexueweif havMoreImage:YES placeHolder:@"请选择学位"];
    
    //出国时间
    NSString *outtime=@"出国时间";
    UILabel *outtimelabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(maymaijorlabel)+25, [self getStringwidth:outtime fontSize:14], 18)];
    [self setLabel:outtimelabel text:outtime rightStar:YES bottomLine:NO];
    
    
    NSArray *timeArr=[NSArray arrayWithObjects:@"3个月",@"6个月",@"1年",@"2年",@"3年",@"不确定", nil];
    
    goAbroadTimeArray=[NSMutableArray array];
    tapIndex=-1;
    selectTime=@"";
    for (int i=0; i<6; i++) {
        int yindex=i/3;
        int xindex=i%3;
        
        UILabel  *timeBtn=[[UILabel alloc]initWithFrame:CGRectMake(viewRight(outtimelabel)+70*xindex+20, viewTop(outtimelabel)-3+yindex*(viewHeight(outtimelabel)+10), 60, viewHeight(outtimelabel)+6)];
        timeBtn.tag=i;
        timeBtn.layer.borderWidth=1;
        timeBtn.layer.borderColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1].CGColor;
        timeBtn.text=timeArr[i];
        timeBtn.textAlignment=NSTextAlignmentCenter;
        timeBtn.font=[UIFont systemFontOfSize:12];
        timeBtn.textColor=[UIColor colorWithRed:194/255.0 green:194/255.0 blue:194/255.0 alpha:1];
        
        [view1 addSubview:timeBtn];
        UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGoabroadTime:)];
        timeBtn.userInteractionEnabled=YES;
        [timeBtn addGestureRecognizer:tap];
        [goAbroadTimeArray addObject:timeBtn];
        
    }
    
    //底部分间线 fengjiexian-x.png
    UIView *timebottomLine=[[UIView alloc]initWithFrame:CGRectMake(10, viewBottom(outtimelabel)+25+viewHeight(outtimelabel)+6, Mainwidth-20, 1)];
    timebottomLine.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"fengjiexian-x.png"]];
    [view1 addSubview:timebottomLine];
    
    //目前学历
    NSString *nowdegree=@"目前学历";
    UILabel *nowdegreelabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(timebottomLine)+6, [self getStringwidth:nowdegree fontSize:14], 18)];
    [self setLabel:nowdegreelabel text:nowdegree rightStar:YES bottomLine:YES];
    
    chosexuelif=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(nowdegreelabel)-5, 200,temheight)];
    [self settextFeild:chosexuelif havMoreImage:YES placeHolder:@"请选择学历"];
    
    //毕业类别
    NSString *majortype=@"毕业类别";
    UILabel *majortypelabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(nowdegreelabel)+25,[self getStringwidth:majortype fontSize:14], 18)];
    [self setLabel:majortypelabel text:majortype rightStar:YES bottomLine:YES];
    
    
    chosebiyeleibief=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(majortypelabel)-5, 200,temheight)];
    [self settextFeild:chosebiyeleibief havMoreImage:YES placeHolder:@"请选择毕业类别"];

    
    //毕业时间
    NSString *majortime=@"毕业时间";
    UILabel *majortimelabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(majortypelabel)+25, [self getStringwidth:majortime fontSize:14], 18)];
    [self setLabel:majortimelabel text:majortime rightStar:YES bottomLine:YES];
    
    biyeshijianf=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(majortimelabel)-5, 200,temheight)];
    [self settextFeild:biyeshijianf havMoreImage:NO placeHolder:@"请输入毕业时间"];
    
    //所学专业
    NSString *suoxuestr=@"所学专业";
    UILabel *suoxuezhuanyelabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(majortimelabel)+25, [self getStringwidth:suoxuestr fontSize:14], 18)];
    [self setLabel:suoxuezhuanyelabel text:suoxuestr rightStar:NO bottomLine:YES];
    
    
    suoxuezhuanyef=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(suoxuezhuanyelabel)-5, 200,temheight)];
    [self settextFeild:suoxuezhuanyef havMoreImage:NO placeHolder:@"请输入所学专业"];
    //在校成绩
    NSString *grade=@"在校成绩";
    UILabel *gradelabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(suoxuezhuanyelabel)+25, [self getStringwidth:grade fontSize:14], 18)];
    [self setLabel:gradelabel text:grade rightStar:NO bottomLine:YES];
    
    zaixiaochengjif=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(gradelabel)-5, 200,temheight)];
    [self settextFeild:zaixiaochengjif havMoreImage:NO placeHolder:@"请输入在校成绩"];
    //语言
    NSString *yuyan=@"语言";
    UILabel *yuyanlabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(gradelabel)+25, [self getStringwidth:yuyan fontSize:14], 18)];
    [self setLabel:yuyanlabel text:yuyan rightStar:YES bottomLine:YES];
    
    
    choseyuyanf=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(yuyanlabel)-5, 200,temheight)];
    [self settextFeild:choseyuyanf havMoreImage:YES placeHolder:@"请选择语言"];
    
    //语言成绩
    NSString *yuyangrade=@"语言成绩";
    UILabel *yuyangradelabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(yuyanlabel)+25, [self getStringwidth:yuyangrade fontSize:14], 18)];
    [self setLabel:yuyangradelabel text:yuyangrade rightStar:YES bottomLine:YES];
    
    yuyanchengjif=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(yuyangradelabel)-5, 200,temheight)];
    [self settextFeild:yuyanchengjif havMoreImage:NO placeHolder:@"请输入语言成绩"];

    //资金担保金额
    NSString *zijin1=@"资金担保金额";
    UILabel *zijinlabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(yuyangradelabel)+25,[self getStringwidth:zijin1 fontSize:14], 18)];
    [self setLabel:zijinlabel text:zijin1 rightStar:YES bottomLine:YES];
    
    zijindanbaof=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(zijinlabel)-5, 200,temheight)];
    [self settextFeild:zijindanbaof havMoreImage:NO placeHolder:@"请输入资金担保金额"];
    
    //其他留学信息
    NSString *otherInfo=@"其他留学信息";
    UILabel *otherInfolabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(zijinlabel)+25, [self getStringwidth:otherInfo   fontSize:14], 18)];
    [self setLabel:otherInfolabel text:otherInfo rightStar:NO bottomLine:NO];
    
   
    
    otherinfof=[[UITextView alloc]initWithFrame:CGRectMake(leftx , viewTop(otherInfolabel),Mainwidth-leftx-14,viewHeight(otherInfolabel)+35)];
    otherinfof.delegate=self;
    [view1 addSubview:otherinfof];
   
    
    otherplaceholder=[[UILabel alloc]initWithFrame:CGRectMake(leftx+2,viewTop(otherinfof)+4, 150, 20)];
    [self setPlacehoder:otherplaceholder text:@"其他留学信息"];
#pragma mark 联系方式
    
    UILabel *topseg1=[[UILabel alloc]initWithFrame:CGRectMake(0,viewBottom(otherInfolabel)+50, Mainwidth, 63/2)];
    [self setTopSeg:topseg1 text:@"联系方式"];

    
    UIView *topbgView1=[[UIView alloc]initWithFrame:CGRectMake(0,viewTop(topseg1)-10, Mainwidth, 10)];
    topbgView1.backgroundColor=[self getCorlor:@"f0f0f0"];
    [view1 addSubview:topbgView1];
    
    //姓名
    NSString *nametest=@"姓名";
    UILabel *namelabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(topseg1)+10, [self getStringwidth:nametest  fontSize:14], 18)];
    [self setLabel:namelabel text:nametest rightStar:YES bottomLine:YES];
    
    namef=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(namelabel)-5, 200,temheight)];
    [self settextFeild:namef havMoreImage:NO placeHolder:@"请输入姓名"];
    
    //性别
    NSString *gendertext=@"性别";
    UILabel *genderlabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(namelabel)+25, [self getStringwidth:gendertext  fontSize:14], 18)];
    [self setLabel:genderlabel text:gendertext rightStar:YES bottomLine:YES];
    
    maleBtn=[[UIButton alloc]initWithFrame:CGRectMake(leftx, viewTop(genderlabel)-3, 60, viewHeight(genderlabel)+10)];
    maleBtn.selected=YES;
    [self setBtn:maleBtn Male:YES];
    
    
    femaleBtn=[[UIButton alloc]initWithFrame:CGRectMake(viewRight(maleBtn)+25, viewTop(genderlabel)-3, 60, viewHeight(genderlabel)+10)];
    [self setBtn:femaleBtn Male:NO];

    
    
    
    //出生年份
    NSString *birthday=@"出生年份";
    UILabel *birthdaylabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(genderlabel)+25, [self getStringwidth:birthday  fontSize:14], 18)];
    [self setLabel:birthdaylabel text:birthday rightStar:YES bottomLine:YES];
    
    
    chosenianfenf=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(birthdaylabel)-5, 200,temheight)];
    [self settextFeild:chosenianfenf havMoreImage:YES placeHolder:@"请选择出生年份"];
    //所在省/直辖市/地区
    
    NSString *sheng=@"所在省/直辖市/地区";
    UILabel *shenglabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(birthdaylabel)+25, [self getStringwidth:sheng  fontSize:14], 18)];
    [self setLabel:shenglabel text:sheng rightStar:YES bottomLine:YES];
    
    
    
    choseshengf=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(shenglabel)-5, 200,temheight)];
    [self settextFeild:choseshengf havMoreImage:YES placeHolder:@"所在省/直辖市/地区"];
    //所在城市
    
    NSString *city=@"所在城市";
    UILabel *citylabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(shenglabel)+25, [self getStringwidth:city  fontSize:14], 18)];
    [self setLabel:citylabel text:city rightStar:YES bottomLine:YES];
   
    chosecityf=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(citylabel)-5, 200,temheight)];
    [self settextFeild:chosecityf havMoreImage:YES placeHolder:@"请选择所在城市"];
    
    //手机
    
    NSString *mobile=@"手机";
    UILabel *mobilelabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(citylabel)+25, [self getStringwidth:mobile  fontSize:14], 18)];
    [self setLabel:mobilelabel text:mobile rightStar:YES bottomLine:YES];
    
    
    shoujif=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(mobilelabel)-5, 200,temheight)];
    [self settextFeild:shoujif havMoreImage:NO placeHolder:@"请输入手机号码"];
    //固定电话
    
    NSString *telephone=@"国定电话";
    UILabel *telephonelabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(mobilelabel)+25, [self getStringwidth:telephone  fontSize:14], 18)];
    [self setLabel:telephonelabel text:telephone rightStar:NO bottomLine:YES];
    
    
    guhuaf=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(telephonelabel)-5, 200,temheight)];
    [self settextFeild:guhuaf havMoreImage:NO placeHolder:@"请输入固定电话号码"];
    //E-mail
    
    NSString *mail=@"E-mail";
    UILabel *maillabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(telephonelabel)+25, [self getStringwidth:mail  fontSize:14], 18)];
    [self setLabel:maillabel text:mail rightStar:YES bottomLine:YES];
    
    
    emailf=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(maillabel)-5, 200,temheight)];
    [self settextFeild:emailf havMoreImage:NO placeHolder:@"请输入E-mail"];
    //QQ
    
    NSString *qq=@"QQ";
    UILabel *qqlabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(maillabel)+25, [self getStringwidth:qq  fontSize:14], 18)];
    [self setLabel:qqlabel text:qq rightStar:NO bottomLine:YES];

    qqf=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(qqlabel)-5, 200,temheight)];
    [self settextFeild:qqf havMoreImage:NO placeHolder:@"请输入QQ号"];
    //MSN
    
    NSString *MSN=@"MSN";
    UILabel *MSNlabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(qqlabel)+25, [self getStringwidth:MSN  fontSize:14], 18)];
    [self setLabel:MSNlabel text:MSN rightStar:NO bottomLine:YES];
    
    
    msnf=[[UITextField alloc]initWithFrame:CGRectMake(leftx, viewTop(MSNlabel)-5, 200,temheight)];
    [self settextFeild:msnf havMoreImage:NO placeHolder:@"请输入MSN号"];
    //备注
    
    NSString *mark=@"备注";
    UILabel *marklabel=[[UILabel alloc]initWithFrame:CGRectMake(17, viewBottom(MSNlabel)+25, [self getStringwidth:mark  fontSize:14], 18)];
    [self setLabel:marklabel text:mark rightStar:NO bottomLine:NO];
    

    
    beizhuinfof=[[UITextView alloc]initWithFrame:CGRectMake(leftx , viewTop(marklabel),Mainwidth-leftx-14,viewHeight(marklabel)+35)];
    [self setTextView:beizhuinfof];
    
    
    notePH=[[UILabel alloc]initWithFrame:CGRectMake(leftx+2,viewTop(beizhuinfof)+4, 150, 20)];
    [self setPlacehoder:notePH text:@"请填写备注信息"];

    
#pragma mark summitButton
    
    
    UILabel *summitlabel=[[UILabel alloc]initWithFrame:CGRectMake(10,viewBottom(marklabel)+60, Mainwidth-20, 63/2)];
    summitlabel.text=@"确认提交";
    summitlabel.font=[UIFont systemFontOfSize:14];
    summitlabel.textColor=[UIColor whiteColor];
    summitlabel.textAlignment=NSTextAlignmentCenter;
    summitlabel.backgroundColor=[self getCorlor:@"48abea"];
    [view1 addSubview:summitlabel];
    summitlabel.userInteractionEnabled=YES;
    UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapToSubmmit)];
    
    [summitlabel addGestureRecognizer:tap];
    
    [view1 setContentSize:CGSizeMake(Mainwidth, viewBottom(summitlabel)+9)];
    
    UIGestureRecognizer *taphideKeyBord=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideKeyBoard)];
    [view1 addGestureRecognizer:taphideKeyBord];
}
-(void)setTopSeg:(UILabel*)seg text:(NSString*)str
{

    seg.text=str;
    seg.font=[UIFont systemFontOfSize:14];
    seg.textColor=[UIColor whiteColor];
    seg.textAlignment=NSTextAlignmentCenter;
    seg.backgroundColor=[self getCorlor:@"48abea"];
    [view1 addSubview:seg];

}
-(void)setPlacehoder:(UILabel*)noteph text:(NSString*)str
{
    noteph.enabled=NO;
    noteph.font=[UIFont systemFontOfSize:14];
    noteph.textColor=kCorlor(176, 176, 176);
    noteph.font=[UIFont systemFontOfSize:14];
    noteph.text=str;
    [view1 addSubview:noteph];

}
-(void)setTextView:(UITextView*)tem
{
    tem.font=[UIFont systemFontOfSize:14];
    tem.delegate=self;
    [view1 addSubview:tem];


}
#pragma mark UITextviewDelegate
- (void)textViewDidChange:(UITextView *)textView
{
    if (textView==otherinfof) {
        if (textView.text.length==0) {
            otherplaceholder.text=@"其他留学信息";
        }
        else{
            otherplaceholder.text=@"";
        }
    }else{
        if (textView.text.length==0) {
            notePH.text=@"请填写备注信息";
        }
        else{
            notePH.text=@"";
        }
    
    }
    

}
-(void)setBtn:(UIButton*)btn  Male:(BOOL)male
{
    genderStr=@"male";
    if (male==YES) {
        
        [btn setTitle:@"男" forState:UIControlStateNormal];
        [btn setTitle:@"男" forState:UIControlStateSelected];
        [btn setImage:[UIImage imageNamed:@"nan1.png"] forState:UIControlStateSelected];
        [btn setImage:[UIImage imageNamed:@"nan2"] forState:UIControlStateNormal];
 
    }else{
    
        [btn setTitle:@"女" forState:UIControlStateNormal];
        [btn setTitle:@"女" forState:UIControlStateSelected];
        [btn setImage:[UIImage imageNamed:@"nv2.png"] forState:UIControlStateSelected];
        [btn setImage:[UIImage imageNamed:@"nv1.png"] forState:UIControlStateNormal];

    
    }
    btn.titleLabel.font=[UIFont systemFontOfSize:13];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [btn setTitleColor:kCorlor(133, 131, 131) forState:UIControlStateNormal];
  
    [btn setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu1.png"]] forUIControlState:UIControlStateSelected];
    [btn setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu2.png"]] forUIControlState:UIControlStateNormal];
    
    if (btn.selected) {
        btn.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu1.png"]];
    }else{
        btn.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu2.png"]];
    
    }
    
    
    btn.layer.borderWidth=1;
    btn.layer.borderColor=kCorlor(239, 239, 239).CGColor;
    [btn addTarget:self action:@selector(tapGenderBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    [view1 addSubview:btn];

}

-(void)tapGenderBtn:(UIButton*)sendr
{
    if (!sendr.selected) {
        sendr.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu1.png"]];
        if (sendr==maleBtn) {
            genderStr=@"male";
            femaleBtn.selected=NO;
            femaleBtn.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu2.png"]];
        }else{
             genderStr=@"female";
            maleBtn.selected=NO;
             maleBtn.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu2.png"]];
        }
        sendr.selected=YES;
            }

}


#pragma mark -tap出国时间
-(void)tapGoabroadTime:(UIGestureRecognizer*)tap
{
    UILabel *tem=[tap view];
    
    if (tapIndex==-1) {
        tapIndex=(int)tem.tag;
        tem.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu1.png"]];
        tem.textColor=[UIColor whiteColor];
//
    }else{
    
        tem.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu1.png"]];
        tem.textColor=[UIColor whiteColor];

    
         UILabel *tem1=goAbroadTimeArray[tapIndex];
        tem1.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu2.png"]];
        tem1.textColor=[UIColor colorWithRed:194/255.0 green:194/255.0 blue:194/255.0 alpha:1];
       tapIndex=(int)tem.tag;
    }
    
    
    switch (tem.tag) {
        case 0://三个月
        {
            selectTime = @"3";
        }
            break;
        case 001://六个月
        {
            selectTime = @"6";
        }
            break;
        case 002://1年
        {
            selectTime = @"12";
        }
            break;
        case 003://2年
        {
            selectTime = @"24";
        }
            break;
        case 004://3年
        {
            selectTime = @"36";
        }
            break;
        case 005://不确定
        {
            selectTime = @"-";
        }
            break;
            
        default:
            break;
    }

    
}


#pragma mark  -确认提交
-(void)tapToSubmmit
{
    NSString *s0=chosecityf.text;//意向国家
    NSString *s1=chosexueweif.text;//我要读的学位
    NSString *s2=selectTime;//出国时间
    NSString *s3=chosexuelif.text;//目前学历
    NSString *s4=chosebiyeleibief.text;//毕业类别
    NSString *s5=biyeshijianf.text;//毕业时间
    NSString *s6=choseyuyanf.text;//语言
    NSString *s7=yuyanchengjif.text;//语言成绩
    NSString *s8=zijindanbaof.text;//担保资金
    NSString *s9=namef.text;//姓名
    NSString *s10=genderStr;//性别
    NSString  *s11=chosenianfenf.text;//出生年份
    NSString  *s12=choseshengf.text;
    NSString *s13=chosecityf.text;
    NSString *s14=shoujif.text;
    NSString *s15=emailf.text;
    
    if ([s0 isEqualToString:@""]||[s1 isEqualToString:@""]||[s2 isEqualToString:@""]||[s3 isEqualToString:@""]||
        [s4 isEqualToString:@""]||[s5 isEqualToString:@""]||[s6 isEqualToString:@""]||[s7 isEqualToString:@""]||
        [s8 isEqualToString:@""]||[s9 isEqualToString:@""]||[s10 isEqualToString:@""]||[s11 isEqualToString:@""]||
        [s12 isEqualToString:@""]||[s13 isEqualToString:@""]||[s14 isEqualToString:@""]||[s15 isEqualToString:@""]) {
       
        hudNull=[[MBProgressHUD alloc]init];
        hudNull.mode=MBProgressHUDModeCustomView;
        hudNull.labelText=@"请填写带星号内容";
        hudNull.labelFont=[UIFont systemFontOfSize:14];
        [self .view addSubview:hudNull];
        [hudNull show:YES];
        [hudNull hide:YES afterDelay:1];
        return;
    }
//
    
    
    if ([self checkInformationIllegal])
    {

    NSMutableDictionary *ds = [NSMutableDictionary dictionary];
    [ds setObject:chosecountryf.text forKey:@"AF_Country"];//意向国家
    [ds setObject:yixiangyuanxiaof.text forKey:@"schoolname"];//意向院校
    [ds setObject:yixiangzhuanyef.text forKey:@"interenst"];//意向专业
    [ds setObject:chosexueweif.text forKey:@"mygrade"];//我的学位
    [ds setObject:selectTime forKey:@"chuguotime"];//出国时间
    [ds setObject:chosexuelif.text forKey:@"cgrade"];//目前学历
    [ds setObject:chosebiyeleibief.text forKey:@"biyetype"];//毕业类别
    [ds setObject:biyeshijianf.text forKey:@"biyeshijian"];//毕业时间
    [ds setObject:suoxuezhuanyef.text forKey:@"zhuanye"];//所学专业
    [ds setObject:zaixiaochengjif.text forKey:@"chengji"];//在校成绩
    [ds setObject:choseyuyanf.text forKey:@"yuyan"];//语言
    [ds setObject:yuyanchengjif.text forKey:@"score"];//语言成绩
    [ds setObject:zijindanbaof.text forKey:@"danbao"];//资金担保
    [ds setObject:otherinfof.text forKey:@"other"];//其他留学信息
    
    [ds setObject:namef.text forKey:@"AF_Name"];//姓名
    [ds setObject:genderStr forKey:@"sex"];//性别
    [ds setObject:chosenianfenf.text forKey:@"borthday"];//出生年份
    //,,,,,,,,,,,,,,,,,,
    [ds setObject:choseshengf.text forKey:@"mycountry"];//所在省/直辖市
    [ds setObject:chosecityf.text forKey:@"AF_City"];//所在城市
    //，，，，，，，，，，
//    [ds setObject:workTimeStr forKey:@"work"];
    [ds setObject:shoujif.text forKey:@"AF_Tel"];//手机
    [ds setObject:guhuaf.text forKey:@"tel"];//固定电话
    [ds setObject:emailf.text forKey:@"email"];//e_mail
    [ds setObject:qqf.text forKey:@"qq"];//qq
    [ds setObject:msnf.text forKey:@"msn"];//msn
    [ds setObject:beizhuinfof.text forKey:@"notes"];//备注
    
    
    
[YHNetwork getInformationWithReguestType:RequestTypePost WithParameters:ds WithApi:@"study/assess" WhenSuccess:^(NSMutableDictionary *response) {
    id tem=response;
    NSLog(@"success==%@",response);
    int code=[[response objectForKey:@"code"]intValue];
    if (code==0) {
        
        [self noticeError:@"提交成功"];
        [self resignItemContent];

    }
    else{
        [self noticeError:@"提交失败"];
    
    }
    
} WhenFailure:^(NSError *failure) {
    
    [self noticeError:@"提交失败"];

    NSLog(@"failure ==%@",failure);
}];
    }
    NSLog(@"taptosubmit");
   }




-(void)setLabel:(UILabel*)lbl text:(NSString*)str rightStar:(BOOL)yseorno bottomLine:(BOOL)yesorno1
{

    lbl.textAlignment=NSTextAlignmentLeft;
    lbl.textColor=[self getCorlor:@"444545"];
    lbl.text=str;
    lbl.font=[UIFont systemFontOfSize:14];
    [view1 addSubview:lbl];
    
   
    
    if (yseorno==YES) {
         [self addrightstar:lbl];
        
    }
    if (yesorno1==YES) {
        [self  addBttomLine:lbl];
    }

}
-(void)settextFeild:(UITextField*)textFeild havMoreImage:(BOOL)isOrNO   placeHolder:(NSString*)str
{
    textFeild.placeholder=str;
    textFeild.font=[UIFont systemFontOfSize:14];
    textFeild.delegate=self;
    [view1 addSubview:textFeild];
    
    [textFeild setValue:kCorlor(176, 176, 176)  forKeyPath:@"_placeholderLabel.textColor"];
    [textFeild setValue:[UIFont boldSystemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];
    
    if (isOrNO==YES) {
        [self addRightImg:textFeild];
        textFeild.inputView=pickerBgview;
    }
    
    
}
-(void)addRightImg:(UIView*)paraview
{
    UIImageView *temview=[[UIImageView alloc]initWithFrame:CGRectMake(Mainwidth-17-33/2, viewTop(paraview)+5, 33/2, 33/2)];
    temview.contentMode=UIViewContentModeScaleAspectFit;
    
    UIImage *img=[UIImage imageNamed:@"gengduo.png"];
    temview.image=img;
    
    [view1 addSubview:temview];
    

}
-(void)addBttomLine:(UIView*)views
{
    UIView *temview=[[UIView alloc]initWithFrame:CGRectMake(10, viewBottom(views)+15, Mainwidth-20, 1)];
    temview.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"fengjiexian-x.png"]];
    [view1 addSubview:temview];

}

-(void)addrightstar:(UIView*)viewt
{
    UIImageView *temview=[[UIImageView alloc]initWithFrame:CGRectMake(viewRight(viewt), viewTop(viewt), 20, viewHeight(viewt))];
    temview.image=[UIImage imageNamed:@"bitian.png"];
    temview.contentMode=UIViewContentModeScaleAspectFit;
    [view1 addSubview:temview];

}


-(CGFloat)getStringwidth:(NSString*)str  fontSize:(CGFloat)font
{

    CGSize detailsize=[str sizeWithFont:[UIFont systemFontOfSize:font] constrainedToSize:CGSizeMake(200, 1000) lineBreakMode:NSLineBreakByCharWrapping];
    return detailsize.width;

}


#pragma mark pickerviewdatasource delegate
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;

}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return pickerShowingArray.count;
   
}


- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{

    return pickerShowingArray[row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    
    temSelectStr=pickerShowingArray[row];
    
}

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    
    if (textField==chosecountryf) {
        picker.typePickerview=TypeYixiangguojia;
       
        pickerShowingArray=yixiangguojiaArray;
         showingtemField=chosecountryf;
        
    }else if (textField==chosexueweif)
    {
        picker.typePickerview=Typexuewei;
        pickerShowingArray=xueweiArray;
         showingtemField=chosexueweif;
    }else if (textField==chosexuelif)
    {
        picker.typePickerview=Typexueli;
         pickerShowingArray=xueliArray;
         showingtemField=chosexuelif;
    }else if (textField==chosebiyeleibief)
    {
        picker.typePickerview=Typebiyeleibie;
         pickerShowingArray=biyeleibieArray;
         showingtemField=chosebiyeleibief;
    }
    else if (textField==choseyuyanf)
    {
        picker.typePickerview=Typeyuyan;
         pickerShowingArray=yuyanArray;
        showingtemField=choseyuyanf;
    }else if (textField==chosenianfenf)
    {
        picker.typePickerview=Typenianfen;
         pickerShowingArray=nianfenArray;
        showingtemField=chosenianfenf;
    }
    else if (textField==choseshengf)
    {
        picker.typePickerview=Typeshengshi;
         pickerShowingArray=shengshiArray;
        showingtemField=choseshengf;
    }else if (textField==chosecityf)
    {
        picker.typePickerview=Typechengshi;
         pickerShowingArray=cityArray;
        showingtemField=chosecityf;
    }

    [picker reloadAllComponents];
    
    
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    return [textField resignFirstResponder];

}

-(void)confirmOrCancel:(UIButton*)sender
{
    
    if (sender.tag==0) {
   
        showingtemField.text=temSelectStr;
        if (picker.typePickerview==Typeshengshi) {
            NSString *path=[[NSBundle mainBundle]pathForResource:[provinceDic objectForKey:temSelectStr] ofType:@"plist"];
            NSDictionary *temdic=[NSDictionary dictionaryWithContentsOfFile:path];
            cityArray=[NSMutableArray arrayWithArray:[temdic allKeys]];
            
            chosecityf.text=@"";
        }
        
    }
   
     [showingtemField resignFirstResponder];

}


-(void)hideKeyBoard
{
    [showingtemField resignFirstResponder];
    [yixiangyuanxiaof resignFirstResponder];
    [yixiangzhuanyef resignFirstResponder];
    [yixiangyuanxiaof resignFirstResponder];
    [biyeshijianf resignFirstResponder];
    [suoxuezhuanyef resignFirstResponder];
    [zaixiaochengjif resignFirstResponder];
    [yuyanchengjif resignFirstResponder];
    [zijindanbaof resignFirstResponder];
    [otherinfof resignFirstResponder];
    [namef resignFirstResponder];
    [shoujif resignFirstResponder];
    [guhuaf resignFirstResponder];
    [emailf resignFirstResponder];
    [qqf resignFirstResponder];
    [msnf resignFirstResponder];
    [beizhuinfof resignFirstResponder];
}
#pragma mark -还原内容
-(void)resignItemContent
{
   
    chosecountryf.text=@"";
    yixiangyuanxiaof.text=@"";
    yixiangzhuanyef.text=@"";
    chosexueweif.text=@"";
    chosexuelif.text=@"";
    selectTime=@"";
    
    
    UILabel *tem=goAbroadTimeArray[tapIndex];
    tem.backgroundColor=[self getCorlor:@"FFFFFF"];
    tem.textColor=[UIColor colorWithRed:194/255.0 green:194/255.0 blue:194/255.0 alpha:1];
    tapIndex=-1;
    
    chosebiyeleibief.text=@"";
    biyeshijianf.text=@"";
    suoxuezhuanyef.text=@"";
    zaixiaochengjif.text=@"";
    choseyuyanf.text=@"";
    yuyanchengjif.text=@"";
    zijindanbaof.text=@"";
    otherinfof.text=@"";
    namef.text=@"";
    
    genderStr=@"male";
    maleBtn.selected=YES;
    [self resignGender:maleBtn];
    femaleBtn.selected=NO;
    [self resignGender:femaleBtn];
    
    
    chosenianfenf.text=@"";
    choseshengf.text=@"";
    chosecityf.text=@"";
    shoujif.text=@"";
    guhuaf.text=@"";
    emailf.text=@"";
    qqf.text=@"";
    msnf.text=@"";
    beizhuinfof.text=@"";
    
}

-(void)resignGender:(UIButton*)btn
{

    if (btn.selected) {
        btn.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu1.png"]];
    }else{
        btn.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"anniu2.png"]];
        
    }

}
#pragma mark -检测要上传的信息是否合法
-(BOOL)checkInformationIllegal
{
    if (![self isPureNumandCharacters:yuyanchengjif.text])
    {
        [self noticeError:@"您输入成绩必须为数字"];
        return NO;
    }
    
    if (![self validateName:namef.text])
    {
        [self noticeError:@"您输入的名字必须为中文"];
        return  NO;
    }
    
    if (![self isPureNumandCharactersAndElevenNumbers:shoujif.text])
    {
        [self noticeError:@"您输入的电话必须为数字且为11位"];
        return NO;
    }
    
    if(![self validateEmail:emailf.text])
    {
        [self noticeError:@"您输入的邮箱不合法"];
        return NO;
    }
    
    
    return YES;
}

-(void)noticeError:(NSString*)str
{
    MBProgressHUD*   huderror=[[MBProgressHUD alloc]init];
    huderror.mode=MBProgressHUDModeCustomView;
    huderror.labelText=str;
    huderror.labelFont=[UIFont systemFontOfSize:14];
    [self .view addSubview:huderror];
    [huderror show:YES];
    [huderror performSelector:@selector(hideHud:) withObject:huderror afterDelay:1];

}


//检验名字是否合法
-(BOOL) validateName:(NSString *)Name
{
    if (Name.length == 0)
    {
        return NO;
    } else
    {
        for(int i=0; i< [Name length];i++)
        {
            int a = [Name characterAtIndex:i];
            if( !(a > 0x4e00 && a < 0x9fff))
                //不是汉字
                return NO;
        }
    }
    
    return YES;
}


//判断必须为11位 且是数字
- (BOOL)isPureNumandCharactersAndElevenNumbers:(NSString *)string
{
  
    if (string.length != 11)
    {
        return NO;
    }
    else
    {
        NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
        NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
        return [phoneTest evaluateWithObject:string];
        
//        string = [string stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
//        if(string.length > 0)
//        {
//            return NO;
//        }
    }
    
    return YES;
}

- (BOOL)isPureNumandCharacters:(NSString *)string
{
    
    string = [string stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
    if(string.length > 0)
    {
        return NO;
    }
    
    return YES;
}

//检验邮箱是否合法
-(BOOL) validateEmail:(NSString *)email
{
    if(email.length == 0)
    {
        return NO;
    }
    else
    {
        NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
        NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
        return [emailTest evaluateWithObject:email];
    }
}


#pragma mark -签证办理
-(void)dealview3
{
//    list-1.png
    UIImageView *leftview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,117/2, viewHeight(view3))];
    leftview.backgroundColor=[self getCorlor:@"edecec"];
    [view3 addSubview:leftview];
    
    
    UIImageView *rithImgView=[[UIImageView alloc]initWithFrame:CGRectMake(viewRight(leftview), 0, Mainwidth-viewWidth(leftview), viewHeight(view3))];
    rithImgView.image=[UIImage imageNamed:@"bg-right.png"];
    [view3 addSubview:rithImgView];
    
    
    [self initQianZheng];
    qianzhengTableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, Mainwidth, viewHeight(view3)) style:UITableViewStylePlain];
    qianzhengTableview.dataSource=self;
    qianzhengTableview.delegate=self;
    qianzhengTableview.backgroundColor=[UIColor clearColor];
    qianzhengTableview.showsVerticalScrollIndicator=NO;
    qianzhengTableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    
    [qianzhengTableview registerClass:[QZTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    [view3 addSubview:qianzhengTableview];
    
//    qianzhengTableview.backgroundView=
    
    
}

-(void)initQianZheng
{

    qianZhengArray=[NSMutableArray array];
    
    switch (self.countryId) {
        case 1://美国
        {
            [qianZhengArray addObject:@"准备签证材料"];
            [qianZhengArray addObject:@"面签协调及预约"];
            [qianZhengArray addObject:@"制定签证方案"];
            [qianZhengArray addObject:@"面签培训"];
            [qianZhengArray addObject:@"获签"];
            [qianZhengArray addObject:@"后续辅导"];
        }
            break;
            
        case 2://澳大利亚
        {
            [qianZhengArray addObject:@"准备签证资料"];
            [qianZhengArray addObject:@"交学费"];
            [qianZhengArray addObject:@"获得澳洲校方确认信（COE）"];
            [qianZhengArray addObject:@"提交电子/纸签证申请"];
            [qianZhengArray addObject:@"体检"];
            [qianZhengArray addObject:@"获签"];
        }
            break;
            
        case 3://英国
        {
            [qianZhengArray addObject:@"换取无条件Offer"];
            [qianZhengArray addObject:@"换取CAS"];
            [qianZhengArray addObject:@"肺结核检查"];
            [qianZhengArray addObject:@"开具存款证明"];
            [qianZhengArray addObject:@"预约签证"];
            [qianZhengArray addObject:@"面试辅导"];
            [qianZhengArray addObject:@"使馆递签"];
            [qianZhengArray addObject:@"顺利获签"];
        }
            break;
            
        case 4://加拿大
        {
            [qianZhengArray addObject:@"向学生了解基本情况"];
            [qianZhengArray addObject:@"发送材料清单"];
            [qianZhengArray addObject:@"准备申请材料"];
            [qianZhengArray addObject:@"签证体检"];
            [qianZhengArray addObject:@"递交签证申请"];
            [qianZhengArray addObject:@"顺利获签"];
        }
            break;
            
        case 13://新西兰
        {
            [qianZhengArray addObject:@"准备签证资料"];
            [qianZhengArray addObject:@"交学费"];
            [qianZhengArray addObject:@"获得澳洲校方确认信（COE）"];
            [qianZhengArray addObject:@"提交电子/纸签证申请"];
            [qianZhengArray addObject:@"体检"];
            [qianZhengArray addObject:@"获签"];
        }
            break;
            
        case 5://欧洲
        {
            //瑞士
            [qianZhengArray addObject:@"在线注册，获得材料清单和申根签证申请表"];
            [qianZhengArray addObject:@"在线预约，准备签证申请材料"];
            [qianZhengArray addObject:@"前往中智签证瑞士受理中心递交材料"];
            [qianZhengArray addObject:@"递交材料"];
            [qianZhengArray addObject:@"交纳签证费及签证服务费"];
            [qianZhengArray addObject:@"查询申请进程"];
            [qianZhengArray addObject:@"领取护照"];
            [qianZhengArray addObject:@"邮寄您的申请材料到TLScontact进行签证申请"];
            
        }
            break;
            
        case 6://亚洲
        {
            //韩国
            [qianZhengArray addObject:@"咨询"];
            [qianZhengArray addObject:@"提供适合学生专业和学校"];
            [qianZhengArray addObject:@"确定专业及学校"];
            [qianZhengArray addObject:@"澳际签约办理相关手续"];
            [qianZhengArray addObject:@"准备申请资料"];
            [qianZhengArray addObject:@"递交院校申请"];
            [qianZhengArray addObject:@"取得大学录取"];
            [qianZhengArray addObject:@"接受和确认大学录取并交纳学费"];
            [qianZhengArray addObject:@"递交签证申请"];
            [qianZhengArray addObject:@"取得返签号码"];
            [qianZhengArray addObject:@"使馆贴签证"];
            [qianZhengArray addObject:@"安排接机住宿"];
            [qianZhengArray addObject:@"抵达韩国"];
            [qianZhengArray addObject:@"完成注册报到手续"];
            [qianZhengArray addObject:@"正式开学"];
        }
            break;
        default:
            break;

    }

}
#pragma mark -院校指南
-(void)dealview2
{
    view2.backgroundColor=kcontentBgcolor;
    
    
    
    rectableview=[[UITableView alloc]initWithFrame:CGRectMake(0,69/2-7, Mainwidth, viewHeight(view2)-69/2+7) style:UITableViewStylePlain];
    rectableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    rectableview.showsVerticalScrollIndicator=NO;
    rectableview.backgroundColor=kcontentBgcolor;
    rectableview.dataSource=self;
    rectableview.delegate=self;
    [rectableview registerClass:[RecTableViewCell class] forCellReuseIdentifier:@"cell"];

   
    [view2 addSubview:rectableview];
    
    
    
   //
    
        [self addSecSegment];
    [self recRequestTyep:0];


}


-(void)recRequestTyep:(int)index
{
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:self.catdir forKey:@"ccode"];
    
    
    switch (index) {
        case 0:
            
            break;
        case 1:
           [dic setObject:@(1) forKey:@"recommend"];
            break;
        case 2:
           [dic setObject:@(1) forKey:@"highschool"];
            break;
        case 3:
            [dic setObject:@(0) forKey:@"highschool"];
            break;
        default:
            break;
    }
    
//    [dic setObject:@"0" forKey:@"lastid"];
    
    ///cent.dsgrd.com/study/school?ccode=us&lastid=0
    
    [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:dic WithApi:@"study/school" WhenSuccess:^(NSMutableDictionary *response) {
        recArray=response;
        [rectableview reloadData];
    } WhenFailure:^(NSError *failure) {
        
    }];


}

-(void)getschoolArea
{

    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:self.catdir forKey:@"ccode"];
    /////study/school/area?ccode=us
    
    schoolAreaArray=[DataSingleTon  shareDataSingleTon].schoolArea;
    
    if (schoolAreaArray.count==0) {
        
        schoolAreaArray=[NSMutableArray array];
        
        [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:dic WithApi:@"study/school/area" WhenSuccess:^(NSMutableDictionary *response) {
            for (id tem in response)
            {
                
                
                [schoolAreaArray addObject:tem];
            }
            [schoolAreaArray insertObject:@"全部" atIndex:0];
          [DataSingleTon  shareDataSingleTon].schoolArea=schoolAreaArray;
            [popview reloadViewWithArray:schoolAreaArray];
        } WhenFailure:^(NSError *failure) {
            
        }];

        
    }
    
    
    

}

-(void)addSecSegment
{
    
    UIView *segmentview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, Mainwidth,69/2)];
    segmentview.backgroundColor=kheadBgcolor;
    [view2 addSubview:segmentview];
    
    
    NSArray *items=[NSArray arrayWithObjects:@"全部",@"推荐学校",@"中学",@"大学",nil];
    
    for (int i=0; i<items.count; i++)
    {
        UILabel *tem=[[UILabel alloc]initWithFrame:CGRectMake(Mainwidth/4*i, 0, Mainwidth/4, 30)];
        tem.text=items[i];
        
        
        [view2 addSubview:tem];
        tem.textAlignment=NSTextAlignmentCenter;
        tem.font=[UIFont systemFontOfSize:13];
        UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapSectsegItem:)];
        tem.userInteractionEnabled=YES;
        [tem addGestureRecognizer:tap];
        tem.tag=i;
        
        if (i==0) {
            tem.frame=CGRectMake(Mainwidth/4*i, 0, [self getStringwidth:@"推荐学校"  fontSize:13]+10, 30);
            citylabel=tem;
            allMoreImg=[[UIButton alloc]initWithFrame:CGRectMake(viewRight(tem),0,20, 30)];
            [allMoreImg setImage:[UIImage imageNamed:@"jiantoushangrec.png"] forState:UIControlStateSelected];
            [allMoreImg setImage:[UIImage imageNamed:@"jiantouxiarec.png"] forState:UIControlStateNormal];
            allMoreImg.userInteractionEnabled=YES;
            [allMoreImg addTarget:self action:@selector(tapAllMoreBtn:) forControlEvents:UIControlEventTouchUpInside];
            
//            UIGestureRecognizer *tapsecSegment=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapSectsegItem:)];
//            [allMoreImg addGestureRecognizer:tapsecSegment];
            
            tem.textColor=kRedColor;
            lastSelectLabel=tem;
            [segmentview addSubview:allMoreImg];
        }else{
            tem.textColor=[UIColor blackColor];
        }
        
        if (i!=0) {
            UIView *yline=[[UIView alloc]initWithFrame:CGRectMake(Mainwidth/4*i, 3, 1, 69/2-6)];
            yline.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"forginStudyfengjiexian-y.png"]];
            [segmentview addSubview:yline];
        }
        
    }
    
    


}

-(CGRect)getStringFrame:(NSString*)str
{

    CGRect rec=[str boundingRectWithSize:CGSizeMake(100, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{
                                                                                                                        NSFontAttributeName:[UIFont systemFontOfSize:13],
                                                                                                                    
                                                                                                                        
                                                                                                                        } context:nil];
    return rec;
}


-(void)tapAllMoreBtn:(UIButton*)sender
{

    if (!sender.selected) {
        sender.selected=YES;
        [self addpopView];
    }else{
        sender.selected=NO;
        [self removePopview];
    }
    

}

-(void)tapSectsegItem:(UIGestureRecognizer*)tap
{

    if (tap.view!=lastSelectLabel) {
        lastSelectLabel.textColor=[UIColor blackColor];
        lastSelectLabel=tap.view;
        lastSelectLabel.textColor=kRedColor;
         [self recRequestTyep:(int)[tap view].tag];
        
        
    }
    if (tap.view.tag!=0) {
        [self removePopview];
    }
    
}




-(void)addpopView
{
    [self getschoolArea];
    if (popview==nil) {
        popview=[[CustomPopTableview alloc]initWithFram:CGRectMake(0, 69/2, Mainwidth, viewHeight(view2)-69/2) dataArry:schoolAreaArray];
        popview.delegatecu=self;
        popview.viewType=TypeRecommend;
    }
    [view2 addSubview:popview];

}

-(void)seletRow:(int)selectIndex
{
    if (selectIndex==0) {
        [self recRequestTyep:0];
        citylabel.text=@"全部";
    }else
    {
        cityId=[[schoolAreaArray[selectIndex] objectForKey:@"id"] intValue];
        citylabel.text=[schoolAreaArray[selectIndex] objectForKey:@"name"] ;
        [self getCiterecData];
    }

    [self removePopview];
}
-(void)removePopview
{

    allMoreImg.selected=NO;
    [popview removeFromSuperview];
}

-(void)getCiterecData
{
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:self.catdir forKey:@"ccode"];
    [dic setObject:@(cityId) forKey:@"areaid"];
    
    
    //    [dic setObject:@"0" forKey:@"lastid"];
    
    ///cent.dsgrd.com/study/school?ccode=us&lastid=0
    
    [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:dic WithApi:@"study/school" WhenSuccess:^(NSMutableDictionary *response) {
        recArray=response;
        [rectableview reloadData];
    } WhenFailure:^(NSError *failure) {
        
    }];

}

///-------------------------------
-(void)tapMoreBtn:(UIButton*)sender
{
    //242
    sender.selected=!sender.selected;
    
    if (sender.selected) {
        [self addMoreCountryView];
        
    }
    else{
        
        [self removeMoreCountryView];
    }
    
    
    
    
    
}

-(void)addMoreCountryView
{
    if (moreCountryView==nil)
    {
        
        itemArray=[NSMutableArray array];
        moreCountryView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, Mainwidth, viewHeight(baseScrollview))];
        [baseScrollview  addSubview:moreCountryView];
        
        UIView *moreView=[[UIView alloc]initWithFrame:CGRectMake(0,0, Mainwidth, 100)];
        moreView.backgroundColor=[UIColor colorWithRed:242/255.0 green:244/255.0 blue:242/255.0 alpha:1];
        [moreCountryView addSubview:moreView];
        
        int rowNum=names.count+1%4==0?(names.count+1)/4:((names.count+1)/4+1);
        
        CGFloat itemWidth=Mainwidth/4;
        
        //gengduguojia.png
        
        
        
        for (int i=0; i<names.count; i++)
        {
            UILabel    *item=[[UILabel alloc]initWithFrame:CGRectMake(5+itemWidth*(i%4),40*(i/4)+10,itemWidth-10, 40)];
            
            
            
            [itemArray addObject:item];
            
            UIImageView *bgImgView=[[UIImageView alloc]initWithFrame:CGRectMake(5+itemWidth*(i%4),40*(i/4)+10,itemWidth-10, 40)];
            bgImgView.image=[UIImage imageNamed:@"gengduguojia.png"];
            [moreView addSubview:bgImgView];
            
            [moreView addSubview:item];
            
                item.text=names[i] ;
                item.tag=i;
            UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapCountryName1:)];
            
            [item addGestureRecognizer:tap];
            item.userInteractionEnabled=YES;
            
            
            item.textAlignment=NSTextAlignmentCenter;
            item.font=[UIFont systemFontOfSize:13];
        }
        
        UIImage *shangHuaImg=[UIImage imageNamed:@"shanghua.png"];
        
        UIImageView *shangHua=[[UIImageView alloc]initWithFrame:CGRectMake(0, 100, Mainwidth, shangHuaImg.size.height*Mainwidth/shangHuaImg.size.width)];
        
        shangHua.contentMode=UIViewContentModeScaleAspectFit;
        shangHua.image=shangHuaImg;
        
        [moreCountryView addSubview:shangHua];
        
    }
        
        
        [baseScrollview addSubview:moreCountryView];
    
    
    
    moreCountryView.frame=CGRectMake(lastBtnInfo*Mainwidth, 0, Mainwidth, 100);
    
    
}
-(void)tapCountryName1:(UIGestureRecognizer*)tap
{
    [self tapSlideSegmentItem:lastBtnInfo currentIndex:(int)tap.view.tag Items:topSegArray];
    baseScrollview.contentOffset=CGPointMake(Mainwidth*tap.view.tag, 0);
    [self removeMoreCountryView];

}

-(void)removeMoreCountryView
{
    moreBtn.selected=NO;
    [moreCountryView removeFromSuperview];
    
}

-(void)tapSlideSegmentItem:(int)lastIndex currentIndex:(int)currentIndex Items:(NSArray*)items
{
    
    
    
    if (currentIndex!=lastIndex) {
        UIButton *temBtn=items[lastIndex];
        temBtn.selected=NO;
        UIButton *temBtn1=items[currentIndex];
        temBtn1.selected=YES;
        UIScrollView *temScrollview=(UIScrollView*)[temBtn1 superview];
        
        if (currentIndex>lastBtnInfo)
        {
            if ((currentIndex+1)*secSegItemWidth+60>viewWidth(temScrollview)) {
                int tem=(int)viewLeft(temBtn1)-2*secSegItemWidth>(int)temScrollview.contentSize.width-(int)viewWidth(temBtn1.superview)?temScrollview.contentSize.width-viewWidth(temScrollview):currentIndex*secSegItemWidth-2*secSegItemWidth;
                temScrollview.contentOffset=CGPointMake(tem, 0);
            }
            
        }
        else if (currentIndex<lastIndex)
        {
            if (currentIndex*secSegItemWidth-60<temScrollview.contentOffset.x) {
                int tem=currentIndex-2>0?currentIndex-2:0;
                temScrollview.contentOffset=CGPointMake(tem*60, 0);
            }
            
            
        }
        
        lastBtnInfo=currentIndex;
    }
    
}

-(void)viewDidAppear:(BOOL)animated
{
    NSLog(@"view2subview=%i",[view2 subviews].count);

}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if (baseScrollview.contentOffset.x>Mainwidth*3) {
        
    }else{
    
    
    }

}

@end
